<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/12/20
  Time: 21:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.shenyun.pojo.Student" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"/>
  <title>学生管理系统-新增学生</title>
  <jsp:include page="/conme/had.jsp" flush="true" />
  <!--开始::内容-->
  <form action="/student/addStudent" method="post">
    <div class="form-group-col-2 mt-20">
      <div class="form-label">学号：</div>
      <div class="form-cont">
        <input type="text" name="number" placeholder="学号" class="form-control form-boxed">
      </div>
    </div>
    <div class="form-group-col-2">
      <div class="form-label">姓名：</div>
      <div class="form-cont">
        <input type="text" name="name" placeholder="姓名" class="form-control form-boxed">
      </div>
    </div>
    <div class="form-group-col-2">
      <div class="form-label">性别：</div>
      <div class="form-cont">
        <label class="radio">
          <input type="radio" name="gender" value="男"/>
          <span>男</span>
        </label>
        <label class="radio">
          <input type="radio" name="gender" value="女"/>
          <span>女</span>
        </label>
      </div>
    </div>
    <div class="form-group-col-2">
      <div class="form-label">年级：</div>
      <div class="form-cont">
        <input type="text" name="grade" placeholder="年级" class="form-control form-boxed">
      </div>
    </div>
    <div class="form-group-col-2">
      <div class="form-label">班级：</div>
      <div class="form-cont">
        <input type="text" name="clbum" placeholder="班级" class="form-control form-boxed">
      </div>
    </div>
    <div class="form-group-col-2">
      <div class="form-label">年龄：</div>
      <div class="form-cont">
        <input type="text" name="age" placeholder="年龄" class="form-control form-boxed">
      </div>
    </div>
    <div class="form-group-col-2">
      <div class="form-label"></div>
      <div class="form-cont">
        <input type="submit" class="btn btn-primary" value="提交" />
        <input type="reset" class="btn btn-secondary" value="重置" />
      </div>
    </div>
  </form>
  <!--结束::内容-->
  <jsp:include page="/conme/footd.jsp" flush="true" />
  <script>
    $(document).ready(function() {
      $('#studentForm').on('submit', function(e) {
        e.preventDefault(); // 阻止表单的默认提交行为

        var formData = {
          number: $('input[name="number"]').val(),
          name: $('input[name="name"]').val(),
          gender: $('input[name="gender"]:checked').val(),
          grade: $('input[name="grade"]').val(),
          clbum: $('input[name="clbum"]').val(),
          age: $('input[name="age"]').val()
        };

        $.ajax({
          url: '/student/addStudent',
          type: 'POST',
          contentType: 'application/json; charset=UTF-8',
          dataType: 'json',
          data: JSON.stringify(formData),
          success: function(response) {
            console.log('Success:', response);
          },
          error: function(xhr, status, error) {
            console.error('Error:', status, error);
          }
        });
      });
    });
  </script>
  </body>
</html>